/**
 * 
 */
package com.xbjtech.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xbjtech.mapper.YzmMapper;
import com.xbjtech.model.Yzm;
import com.xbjtech.service.YzmService;
import com.xbjtech.util.StringUtils;

/**
 * @author Administrator
 *
 */
@Service
public class YzmServiceImpl implements YzmService {

	@Autowired
	YzmMapper yzmMapper;
	
	@Override
	@Transactional(timeout = 5)
	public Yzm randomYzm() {
		Yzm yzm = new Yzm();
		yzm.setYzm(StringUtils.randomNumString(9));
		yzm.setCreateTime(new Date());
		try {
			yzmMapper.insertYzm(yzm);
			return yzm;
		} catch (RuntimeException e) {
			return randomYzm();
		}
	}

	/* (non-Javadoc)
	 * @see com.xbjtech.service.YzmService#updateYzm(com.xbjtech.model.Yzm)
	 */
	@Override
	public void updateYzm(Yzm yzm) {
		yzmMapper.updateYzm(yzm);
	}

	/* (non-Javadoc)
	 * @see com.xbjtech.service.YzmService#selectYzm(java.lang.String)
	 */
	@Override
	public Yzm selectYzm(String yzm) {
		return yzmMapper.selectYzmByHxm(yzm);
	}

}
